import { defineStore } from 'pinia';

export const useUserStore = defineStore('user', {
  state: () => {
    return {
      _id: '', //本用户id
      area: '天津',
      location: '健康街10号',
      name: '张随缘',
      phone: '158-1569-5698',
      avatar: '',
      works: [
        {
          status: '已评价',
          title: '摄像头维修',
          _id: '111111111111',
          phone: 12345678901,
          startedAt: Date.now(), //时间戳
          price: 1200.00,
          tip: 300.00,
          location: '重庆市九龙坡区石桥铺西亚商务大厦7-2',
        }
      ],
      publishes: [{
        status: '已评价',
        title: '摄像头维修',
        _id: '111111111111',
        phone: 12345678901,
        startedAt: Date.now(), //时间戳
        price: 1200.00,
        tip: 300.00,
        location: '重庆市九龙坡区石桥铺西亚商务大厦7-2',
        workers: [{ _id: '000001', name: '张随缘' }, { _id: '000002', name: '张' }, { _id: '000003', name: '随缘' }],
      }],
      status: false,
      IDNumber: '3274794279437932798'
    };
  },
  // 也可以这样定义
  // state: () => ({ count: 0 })
  actions: {
    getUser() {
      return new Promise((resolve, reject) => {
        uni.request({
          url: '/user',
          success: ({ data }) => {
            this.$patch(data)
            resolve()
          },
          fail: () => {
            reject()
          }
        })
      })
    },

    getMyPublish() {
      uni.request({
        url: '/order/owner/',
        success: ({ data }) => {
          this.publishes = data
          console.log(data)
        }
      })
    },

    getMyWorks() {
      uni.request({
        url: '/apply/worker/' + this._id,
        success: ({ data }) => {
          this.works = data
          console.log(data)
        }
      })
    }

  },
});